<!--资金池/自动拆借管理查询录入页面-->
<template>
  <div class="app-container">
    <div style="width: 1024px; margin: 10px auto">
      <el-form ref="entryForm" :model="formData" :rules="rules" label-width="126px" style="margin-top: 40px">
        <el-row v-if="this.formData.rspId">
          <el-col :span="24">
            <el-form-item label="交易流水号" prop="rspId">
              <el-input v-model="formData.rspId" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="发起参与机构号：" prop="sender">
              <el-input v-model="formData.sender" placeholder="发起参与机构号" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发起参与机构名称：" prop="senderName">
              <el-input v-model="formData.senderName" placeholder="发起参与机构名称" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="查询类型：" prop="inqType">
              <el-select v-model="formData.inqType" placeholder="请选择" style="width: 100%" :disabled="isforbid">
                <el-option
                  v-for="dict in dictMap.QUERY_TYPE_614"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="清算日期：" prop="clrDate">
              <el-date-picker
                :disabled="isforbid"
                v-model="formData.clrDate"
                type="date"
                value-format="yyyyMMdd"
                placeholder="选择日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注：" prop="remarks">
              <el-input
                type="textarea"
                v-model="formData.remarks"
                show-word-limit
                maxlength="256"
                :disabled="isforbid"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="bottom-control">
        <el-button type="primary" @click="submitFn" :loading="isLoading" v-if="!this.formData.rspId">提交</el-button>
        <el-button type="warning" @click="resetFn">重置</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import { save } from "@/api/cnaps/saps/poolingAndAutoMng/funds_borrow_entry.js";
import { listPageMixin } from "@/libs/listPageMixin";
import { log } from "util";
import { mapGetters } from "vuex";

export default {
  name: "fundsBorrowEntry",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      isforbid: false,
      isLoading: false,
      //数据字典
      searchFormDictList: ["QUERY_TYPE_614"],
      formData: {
        rspId: "",
        sender: "",
        senderName: "",
        inqType: "G107",
        remarks: "",
      },
      rules: {
        inqType: [
          {
            required: true,
            message: "必填",
            trigger: "change",
          },
        ],
        clrDate: [
          {
            required: true,
            message: "必填",
            trigger: "change",
          },
        ],
      },
    };
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  watch: {
    globalBusData: {
      handler(val) {
        const dateCurrent = new Date();
        const Y = dateCurrent.getFullYear(); // 年
        const M = this.prefixZero(dateCurrent.getMonth() + 1); // 月
        const D = this.prefixZero(dateCurrent.getDate()); // 日
        let dateFull = Y + M + D;
        console.log(val, dateFull, "全局变量");
        this.$set(this.formData, "sender", val.cnapsBrno);
        this.$set(this.formData, "senderName", val.cnapsBrname);
        this.$set(this.formData, "clrDate", dateFull);
      },
      deep: true,
      immediate: true,
    },
  },
  mounted() {},
  methods: {
    prefixZero(num = 0, n = 2) {
      // 数字位数不够，数字前面补零
      return (Array(n).join("0") + num).slice(-n);
    },
    reset() {
      this.resetForm("entryForm");
      //   this.$set(this, "formData", {});
    },
    submitFn() {
      this.$refs["entryForm"].validate((valid) => {
        if (valid) {
          this.isLoading = true;
          save(this.formData)
            .then((res) => {
              this.isLoading = false;
              this.$set(this.formData, "rspId", res.result.rspId);
              this.isforbid = true;
              console.log(res, "提交成功！");
              this.msgSuccess("提交成功！");
            })
            .catch((err) => {
              this.isLoading = false;
            });
        }
      });
    },
    resetFn() {
      if (this.formData.rspId) {
        this.isforbid = false;
      }

      this.reset();
      this.$set(this.formData,"rspId","");
      this.$set(this.formData, "sender", this.globalBusData.cnapsBrno);
      this.$set(this.formData, "senderName", this.globalBusData.cnapsBrname);
    },
  },
};
</script>
<style lang="scss" scoped>
.bottom-control {
  margin: 20px 0;
  text-align: center;
}
</style>
